package com.freecloud.javabasics.thread.state;

import java.util.concurrent.TimeUnit;

/**
 * 线程复位（异常）
 * @Author: maomao
 * @Date: 2020-01-21 17:04
 */
public class ExceptionThreadDemo {
    private static int i;

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                try {
                    //中断一个处于阻塞状态的线程
                    //不使用该代码输出为true 使用后为false
                    TimeUnit.SECONDS.sleep(2);
                    System.out.println("demo");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    //处理阻塞结束
                    //break;
                }
            }
            System.out.println("i : " + i);
        });
        thread.start();

        TimeUnit.SECONDS.sleep(1);
        thread.interrupt();

        System.out.println(thread.isInterrupted());
    }
}
